import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class TestDemo {
	//汉诺塔
    public static void move(char pos1,char pos2) {
        System.out.println(pos1+"->"+pos2+"");
    }
    public static void hanio(int n,char pos1,char pos2,char pos3) {
        if (n == 1) {
            move(pos1,pos3);
        }else{
            hanio(n-1,pos1,pos3,pos2);
            move(pos1,pos3);
            hanio(n-1,pos2,pos1,pos3);
        }
    }
    public static void main1(String[] args) {
        hanio(1,'A','B','C');
        System.out.println();
        hanio(2,'A','B','C');
        System.out.println();
        hanio(3,'A','B','C');
        System.out.println();
    }

    public static void main2(String[] args) {
        int[]array={1,2,3,4,5,6};
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+"");
        }
        System.out.println();
        for (int x:array) {
            System.out.print(x+"");
        }
        System.out.println();
        //将参数的数组以字符串的形式进行输出
        String ret=Arrays.toString(array);
        System.out.println(ret);
    }

    public static int[] transform(int[] array) {
        int[] ret=new int[array.length];
        for (int i = 0; i < array.length; i++) {
            ret[i]=2*array[i];
        }
        return ret;
    }

    public static void main3(String[] args) {
        int[] array={1,2,3,4,5};
        int[] ret2=transform(array);
        System.out.println(Arrays.toString(ret2));
    }
    //斐波那契 递归
    public static int fib(int n) {
        if(n==1||n==2){
            return 1;
        }else{
            return fib(n-1)+fib(n-2);
        }

    }
    public static void main(String[] args) {
        System.out.println(fib(1));
        System.out.println(fib(2));
        System.out.println(fib(3));
        System.out.println(fib(45));
    }
    //斐波那契数,写非递归的
    public static int fib2(int n) {
        if(n==1||n==2){
            return 1;
        }
        int f1=1;
        int f2=1;
        int f3=0;
        for (int i = 3; i <=n ; i++) {
            f3=f1+f2;
            f1=f2;
            f2=f3;
        }
        return f3;
    }

    public static void main6(String[] args) {
        System.out.println(fib2(1));
        System.out.println(fib2(2));
        System.out.println(fib2(3));
        System.out.println(fib2(45));
    }
    //青蛙跳台阶
    public static int frogJump(int n) {
        if(n==1||n==2){
            return n;
        }
        int f1=1;
        int f2=2;
        int f3=0;
        for (int i = 3; i <=n ; i++) {
            f3=f1+f2;
            f1=f2;
            f2=f3;
        }
        return f3;
    }

    public static void main5(String[] args) {
        System.out.println(frogJump(1));
        System.out.println(frogJump(2));
        System.out.println(frogJump(3));
        System.out.println(frogJump(4));
    }
//二分查找
    public static int binarySearch(int[]array,int key) {
        int left=0;
        int right= array.length-1;
        while(left<=right){
            int mid=(left+right)/2;
            if(array[mid]>key){
                right=mid-1;
            }else if (array[mid]<left){
                left=mid+1;
            }else{
                return mid;
            }
        }
        return -1;
    }
    public static void main7(String[] args) {
        int[] array={1,2,3,4,5,15,19};
        System.out.println(binarySearch(array,2));
    }

    //求最大重载
    public static int maxInt(int a,int b) {
        if (a>b){
            return a;
        }else{
            return b;
        }
    }
    public static double maxDouble(double j,double k) {
        if (j>k){
            return j;
        }else{
            return k;
        }
    }
    public static void cmpDouble(double j,double k,int a) {
        double temp=j>k?j:k;
        double max=temp>a?temp:a;
        double temp1=j<k?j:k;
        double min=temp1<a?temp1:a;
        double mid=j+k+a*1.0-max-min;
        System.out.println(max+">"+mid+">"+min);
    }
    public static void main8(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.print("请输入第一个整数：");
        int a=scanner.nextInt();
        System.out.print("请输入第二个整数：");
        int b=scanner.nextInt();
        System.out.print("请输入第一个小数：");
        double j= scanner.nextDouble();
        System.out.print("请输入第二个小数：");
        double k= scanner.nextDouble();
        System.out.print("两个整数最大值：");
        System.out.println(maxInt(a,b));
        System.out.print("两个小数最大值：");
        System.out.println(maxDouble(j,k));
        cmpDouble(j,k,a);
    }
    //求和的重载
    public static int sumInt(int a,int b) {
       return a+b;
    }
    public static double sumDouble(double j,double k,double l) {
        return j+k+l;
    }
    public static void main9(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.print("请输入第一个整数：");
        int a=scanner.nextInt();
        System.out.print("请输入第二个整数：");
        int b=scanner.nextInt();
        System.out.print("请输入第一个小数：");
        double j= scanner.nextDouble();
        System.out.print("请输入第二个小数：");
        double k= scanner.nextDouble();
        System.out.print("请输入第三个小数：");
        double l= scanner.nextDouble();
        System.out.print("两个整数的和：");
        System.out.println(sumInt(a,b));
        System.out.print("三个小数的和：");
        System.out.println(sumDouble(j,k,l));
    }
    }



























